home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / Lattice C v5.02 d4.adf / examples / cat.c < prev    next >
C/C++ Source or Header  |  1988-11-07  |  598b  |  33 lines

  1.   /* (This program is from p. 154 of the Kernighan and Ritchie text */
  2. #include <stdio.h>
  3.  
  4. main(argc, argv)    /* cat: concatenate files */
  5. int argc;
  6. char *argv[];
  7. {
  8.     FILE *fp, *fopen();
  9.  
  10.     if (argc == 1) /* no args; copy standard input */
  11.      filecopy(stdin);
  12.     else
  13.      while (--argc > 0)
  14.         if ((fp = fopen(*++argv, "r")) == NULL) {
  15.         fprintf(stderr,
  16.             "cat: can't open %s\n", *argv);
  17.         exit(1);
  18.         } else {
  19.         filecopy(fp);
  20.         fclose(fp);
  21.         }
  22.     exit(0);
  23. }
  24.  
  25. filecopy(fp)    /* copy file fp to standard output */
  26. FILE *fp;
  27. {
  28.     int c;
  29.  
  30.     while ((c = getc(fp)) != EOF)
  31.     putc(c, stdout);
  32. }
  33.